package com.yc.jpyy.dataacquisitionSum.service.imp;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.base.service.BaseService;
import com.yc.jpyy.dataacquisitionSum.dao.DataAcquisitionSumDao;
import com.yc.jpyy.dataacquisitionSum.service.DataAcquisitionSumService;


@Service
public class DataAcquisitionSumServiceImpl extends BaseService implements DataAcquisitionSumService {
 

@Autowired
private DataAcquisitionSumDao dataAcquisitionSumDao;



@Override
public Map<String, Object> addDataAcquisitionSum(List<Map<String,Object>> dataList)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int count = dataAcquisitionSumDao.addDataAcquisitionSum(dataList);
	if(count <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "新增失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "新增成功");
	}
	return resultMap;
}

@Override
public Map<String, Object> selectDataAcquisitionSumByPage(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
	int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
	paramsMap.put("pagestart", (pagenum-1) * pagesize);
	String companyid = Optional.ofNullable(paramsMap.get("companyid")).orElse("").toString();
	paramsMap.put("companyid", companyid.equals("")?"":companyid.split(","));
	List<Map<String,Object>> dataList = dataAcquisitionSumDao.selectDataAcquisitionSumByPage(paramsMap);
	int dataCounts = dataAcquisitionSumDao.selectDataAcquisitionSumCount(paramsMap);
	if(dataList != null && dataList.size() > 0){
		resultMap.put("returnCode", 1);
		resultMap.put("ListData",dataList);
		resultMap.put("TotalCount",dataCounts);
		resultMap.put("TotalPage",dataCounts % pagesize >0 ? dataCounts/pagesize + 1 : dataCounts/pagesize);
		resultMap.put("returnMsg", "操作成功");
	}else{
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "系统无数据");
	}
	return resultMap;
}

@Override
public Map<String, Object> delDataAcquisitionSum(Map<String, Object> paramsMap)
		throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	paramsMap.put("ids", paramsMap.get("ids").toString().split(","));
	int count = dataAcquisitionSumDao.delDataAcquisitionSum(paramsMap);
	if(count <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "删除失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "删除成功");
	}
	return resultMap;
}

@Override
public Map<String,Object> updateDataAcquisitionSumDao(Map<String, Object> companyInfo) throws DataAccessException {
	Map<String,Object> resultMap = new HashMap<>();
	int ret = dataAcquisitionSumDao.updateDataAcquisitionSumDao(companyInfo);
	if(ret <= 0){
		resultMap.put("returnCode", 0);
		resultMap.put("returnMsg", "更新失败");
	}else{
		resultMap.put("returnCode", 1);
		resultMap.put("returnMsg", "更新成功");
	}
	return resultMap;
}

}
